package pattern.behavior.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author : Rookie
 * @description : 具体的主题类
 * @date : 2023/8/26
 */
public class ConcreteSubject implements Subject{
    /**
     * 所有的观察者
     */
    private List<pattern.behavior.observer.Observer> observers = new ArrayList<>();

    @Override
    public void registerObserver(Observer observer) {
        observers.add(observer);
    }

    @Override
    public void removeObserver(Observer observer) {
        observers.remove(observer);
    }

    @Override
    public void notifyObservers() {
        observers.forEach(Observer::update);
    }
}
